From 98170335a7f246ccd23efb1578e9d0feabb7be14 Mon Sep 17 00:00:00 2001 From: "Herman J. Radtke III" Date: Mon, 8 May 2017 22:30:23 -0700 Subject: [PATCH] fixes - fix glob missing members test to use proper expectations - update code to handle case where glob does not match anything --- src/cargo/core/workspace.rs | 15 +++++++++++---- tests/workspaces.rs | 13 ++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 0054586c9..6c81bd8e8 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -322,8 +322,16 @@ impl<'cfg> Workspace<'cfg> { let mut expanded_list = Vec::new(); for path in list { - let expanded_paths = expand_member_path(&path, root)?; - expanded_list.extend(expanded_paths); + let pathbuf = root.join(path); + let expanded_paths = expand_member_path(&pathbuf)?; + + // If glob does not find any valid paths, then put the original + // path in the expanded list to maintain backwards compatibility. + if expanded_paths.is_empty() { + expanded_list.push(pathbuf); + } else { + expanded_list.extend(expanded_paths); + } } for path in expanded_list { @@ -536,8 +544,7 @@ impl<'cfg> Workspace<'cfg> { } } -fn expand_member_path(member_path: &str, root_path: &Path) -> CargoResult> { - let path = root_path.join(member_path); +fn expand_member_path(path: &Path) -> CargoResult> { let path = path.to_str().unwrap(); let res = glob(path).map_err(|e| { human(format!("could not parse pattern `{}`: {}", &path, e)) diff --git a/tests/workspaces.rs b/tests/workspaces.rs index 4a1f3bb63..4670d28f7 100644 --- a/tests/workspaces.rs +++ b/tests/workspaces.rs @@ -1444,7 +1444,7 @@ fn glob_syntax() { } #[test] -fn glob_syntax_non_cargo_folder() { +fn glob_syntax_invalid_members() { let p = project("foo") .file("Cargo.toml", r#" [project] @@ -1459,10 +1459,13 @@ fn glob_syntax_non_cargo_folder() { .file("crates/bar/src/main.rs", "fn main() {}"); p.build(); - assert_that(p.cargo("build"), execs().with_status(0)); - assert_that(&p.bin("foo"), existing_file()); - assert_that(&p.bin("bar"), is_not(existing_file())); + assert_that(p.cargo("build"), + execs().with_status(101) + .with_stderr("\ +error: failed to read `[..]Cargo.toml` - assert_that(&p.root().join("Cargo.lock"), existing_file()); +Caused by: + [..] +")); } -- 2.30.2